<template>
  <div>
    <!-- {{ this.$route.query.id }} -->
    <div class="bote" @click="$router.back()">
      <p><van-icon name="arrow-left" /></p>
      <p style="margin-left: 30vw">{{ this.$route.query.id }}</p>
    </div>
    <div
      class="view"
      v-for="(seaitem, index) in list"
      :key="index"
      :seaitem="seaitem"
    >
      <div class="box" v-if="!(seaitem.r?.n || seaitem.r?.tips)">
        <van-empty image="search" description="搜索中" />
      </div>
      <div
        class="box"
        @click="
          addLishi(seaitem),
            $router.push({
              path: '/xiangqing',
              query: {
                id: seaitem?.r?.id || seaitem?.note?.id || seaitem?.r?.vc,
              },
            })
        "
      >
        <div class="left">
          <van-image
            width="100rem"
            height="90rem"
            fit="cover"
            :src="seaitem.r?.img || seaitem.r?.p"
          />
        </div>
        <div class="right">
          <h1>{{ seaitem.r?.n || seaitem.r?.tips }}</h1>
          <div class="xingrong">{{ seaitem.r?.cookstory }}</div>
          <div class="hz">
            <p>{{ seaitem.r?.recommendation_tag }}</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Vue from "vue";
import { Image as VanImage } from "vant";

Vue.use(VanImage);
export default {
  data() {
    return {
      list: [],
      cookid: [],
      itemts: JSON.parse(window.localStorage.getItem("itemts")) || [],
    };
  },
  computed: {
    isCollection: function () {
      const arr =
        this.itemts.filter((o) => {
          return o.ckid === this.itemts.id;
        }) || [];
      return arr.length > 0 ? true : false;
    },
  },
  created() {
    this.axios
      .get(
        "https://apis.netstart.cn/douguo/recipe/search?keyword=" +
          this.$route.query.id
      )
      .then((res) => {
        this.list = res.data.result.list;
        // console.log("this.list",this.list);
      });
  },
  methods: {
    addLishi(seaitem) {
      // console.log(seaitem.r.id);
      this.cookid = seaitem.r.id;
      // console.log("cookid", this.cookid);
      this.itemts = [{ ckid: `${this.cookid}` }, ...this.itemts];
      window.localStorage.setItem("itemts", JSON.stringify(this.itemts));
    },
  },
};
</script>

<style lang="scss" scoped>
.bote {
  width: 100vw;
  box-sizing: border-box;
  background-color: #f5f5f5;
  position: fixed;
  top: 0;
  display: flex;
  font-size: 23rem;
  padding-left: 3rem;
  line-height: 45rem;
  z-index: 999;
  p {
    display: flex;
    align-items: center;
  }
}
.van-image {
  img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
  }
}
.view {
  margin-top: 45rem;
}
.box {
  display: flex;
  .right {
    height: 100rem;
    position: relative;
    h1 {
      white-space: nowrap;
      font-size: 16rem;
      font-weight: 700;
      margin: 15rem 0 0 10rem;
      color: #777;
    }
    .xingrong {
      // height: 30rem;
      width: 230rem;
      margin: 5rem 0 0 10rem;
      font-size: 12rem;
      overflow: hidden;
      -webkit-line-clamp: 3;
      display: -webkit-box;
      -webkit-box-orient: vertical;
    }
    .hz {
      position: absolute;
      bottom: 10rem;
      left: 10rem;
    }
  }
}
</style>
